#!./common/bats/bin/bats
# -*-sh-*-

export BATS_JUNIT_CLASS=Singularity
source ./common/test_helper_functions.bash || exit 1
source ./common/functions || exit 1

if [ -s ./common/TEST_ENV ];then
    source ./common/TEST_ENV
fi

check_rms
rm=$RESOURCE_MANAGER
module purge || exit 1
module load singularity || exit 1
ARCH=`uname -m`
echo $ARCH > foo.out
if [ "$ARCH" == "aarch64" ];then
    export DOCKER_ARCHITECTURE=arm64
fi

DISTRO=ubuntu
IMAGE=./${DISTRO}.sif

@test "[singularity] check for RPM" {
    check_if_rpm_installed "singularity${DELIM}"
}

@test "[singularity] pull down $DISTRO docker image" {
    rm -f ${IMAGE}

    singularity pull ${IMAGE} docker://${DISTRO}:latest

    run test -s ${IMAGE}
    assert_success
}

@test "[singularity] exec image" {
    singularity exec ${IMAGE} cat /etc/os-release | grep "^ID=${DISTRO}" 
    assert_success
}

@test "[singularity] exec image via $rm" {
    run_serial_binary singularity exec ${IMAGE} cat /etc/os-release
    assert_success

    rm -f ${IMAGE}
}
